<template>
  <div class="app-container">
    <!-- 输入表单 -->
    <el-form label-width="120px">
      <el-form-item label="借款额度">
        <el-input-number v-model="integralGrade.borrowAmount" :min="0" />
      </el-form-item>
      <el-form-item label="积分区间开始">
        <el-input-number v-model="integralGrade.integralStart" :min="0" />
      </el-form-item>
      <el-form-item label="积分区间结束">
        <el-input-number v-model="integralGrade.integralEnd" :min="0" />
      </el-form-item>
      <el-form-item>
        <el-button
          :disabled="saveBtnDisabled"
          type="primary"
          @click="saveOrUpdate()"
        >
          保存
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { save, getById,updateById } from '@/api/core/integral-grade'
export default {
  name: '',
  data() {
    return {
      //积分等级对象
      integralGrade: {},
      saveBtnDisabled: false, //是否禁用保存按钮
    }
  },
  created() {
    if (this.$route.params.id) {
      this.fatchById(this.$route.params.id)
    }
  },
  methods: {
    saveOrUpdate() {
      //禁用保存
      this.saveBtnDisabled = true

      if (!this.integralGrade.id) {
        //insert
        this.saveData()
      } else {
        //update
        this.updateData()
      }
    },

    saveData() {
      save(this.integralGrade).then((resp) => {
        this.$message.success(resp.message)
        this.$router.push('/core/integral-grade/list')
      })
    },

    updateData() {
        updateById(this.integralGrade).then((resp) => {
        this.$message.success(resp.message)
        this.$router.push('/core/integral-grade/list')
      })
    },

    fatchById(id) {
      getById(id).then((resp) => {
        this.integralGrade = resp.data
      })
    },
  },
  mounted() {},
}
</script>

<style scoped>
</style>
